
package com.bjtu.literatureclient.util.create;

public class Creates {

    public static final int CHINESE = 0;

    public static final int ENGLISH = 1;
    public String[] getDividedNames(String str) {
        String[] strs = new String[3];
        if (!str.equals("")) {

            // ֻ��һ���ո񣬼����м���
            if (str.indexOf(" ") == str.lastIndexOf(" ")) {
                strs[0] = str.substring(0, str.indexOf(" "));
                strs[1] = "";
                strs[2] = str.substring(str.lastIndexOf(" ") + 1,
                        str.length());
            } else {
                strs[0] = str.substring(0, str.indexOf(" "));
                strs[1] = str.substring(str.indexOf(" ") + 1,
                        str.lastIndexOf(" "));
                strs[2] = str.substring(str.lastIndexOf(" ") + 1,
                        str.length());
            }
        } else {
            strs[0] = "";
            strs[1] = "";
            strs[2] = "";
        }

        // ɾ���ո�
        for (int i = 0; i < strs.length; i++) {
            if (strs[i].equals(" "))
                strs[i] = "";
        }

        return strs;
    }

    public String[] getDividedNames2(String name, String lastName,
            String firstName) {
        String strs[] = new String[2];

        if (!name.equals("")) {
            int i;
            for (i = 1; i < name.length(); i++) {
                String lName = name.substring(0, i);
                if (CnToSpell.getFullSpell(lName).equals(lastName)) {
                    strs[0] = lName;
                    break;
                }

            }
            strs[1] = name.substring(i, name.length());
        } else {
            strs[0] = "";
            strs[1] = "";
        }
        return strs;
    }

    /**
     * �õ�һ���ַ����Ĵ�д����ĸ
     * 2011-10-08
     * 
     * @author Lei Xia
     */
    public String getFirstLetter(String str) {
        String firstLetter = "";
        if (!str.equals("")) {
            firstLetter = str.substring(0, 1);
            firstLetter = firstLetter.toUpperCase();
        }

        return firstLetter;
    }

    /**
     * ��һ���ַ���������ĸ��д
     * 2011-10-08
     * 
     * @author Lei Xia
     */
    public String toUpperCaseFirstLetter(String str) {
        String firstLetter = "";
        String latterString = "";
        if (!str.equals("")) {
            firstLetter = str.substring(0, 1);
            latterString = str.substring(1, str.length());
            firstLetter = firstLetter.toUpperCase();
        }

        return (firstLetter + latterString);
    }

    /**
     * �õ�ISBN�ĸ�������
     * 
     * @param ISBN
     * @return
     * @time: 2012-5-20/����10:20:26
     */
    public String[] getAllPartOfISBN(String ISBN) {
        String[] parts = new String[5];
        for (int i = 0; i < 4; i++) {
            int index = ISBN.indexOf("-", 0);
            parts[i] = ISBN.substring(0, index);
            ISBN = ISBN.substring(index + 1);
        }
        parts[4] = ISBN.substring(0);
        return parts;
    }

}
